home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbzerarc.c,v < prev   
Encoding:
Text File  |  1990-02-15  |  6.5 KB  |  261 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.28;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/************************************************************
  27. Copyright 1989 by The Massachusetts Institute of Technology
  28.  
  29. Permission to use, copy, modify, and distribute this
  30. software and its documentation for any purpose and without
  31. fee is hereby granted, provided that the above copyright
  32. notice appear in all copies and that both that copyright
  33. notice and this permission notice appear in supporting
  34. documentation, and that the name of MIT not be used in
  35. advertising or publicity pertaining to distribution of the
  36. software without specific prior written permission.
  37. M.I.T. makes no representation about the suitability of
  38. this software for any purpose. It is provided "as is"
  39. without any express or implied warranty.
  40.  
  41. ********************************************************/
  42.  
  43. /* $XConsortium: mfbzerarc.c,v 5.10 89/09/20 18:55:33 rws Exp $ */
  44.  
  45. /* Derived from:
  46.  * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
  47.  * by M. L. V. Pitteway
  48.  * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
  49.  */
  50.  
  51. #include "X.h"
  52. #include "Xprotostr.h"
  53. #include "miscstruct.h"
  54. #include "gcstruct.h"
  55. #include "pixmapstr.h"
  56. #include "scrnintstr.h"
  57. #include "mfb.h"
  58. #include "maskbits.h"
  59. #include "mizerarc.h"
  60.  
  61. extern void miPolyArc(), miZeroPolyArc();
  62.  
  63. #if (BITMAP_BIT_ORDER == MSBFirst)
  64. #define LEFTMOST    ((unsigned int) 0x80000000)
  65. #else
  66. #define LEFTMOST    ((unsigned int) 1)
  67. #endif
  68.  
  69. #define PixelateWhite(addr,off) \
  70.     (addr)[(off)>>5] |= SCRRIGHT (LEFTMOST, ((off) & 0x1f))
  71. #define PixelateBlack(addr,off) \
  72.     (addr)[(off)>>5] &= ~(SCRRIGHT (LEFTMOST, ((off) & 0x1f)))
  73.  
  74. #define Pixelate(base,off) \
  75. { \
  76.     paddr = base + ((off)>>5); \
  77.     pmask = SCRRIGHT(LEFTMOST, (off) & 0x1f); \
  78.     *paddr = (*paddr & ~pmask) | (pixel & pmask); \
  79. }
  80.  
  81. #define DoPix(bit,base,off) if (mask & bit) Pixelate(base,off);
  82.  
  83. static void
  84. mfbZeroArcSS(pDraw, pGC, arc)
  85.     DrawablePtr pDraw;
  86.     GCPtr pGC;
  87.     xArc *arc;
  88. {
  89.     miZeroArcRec info;
  90.     Bool do360;
  91.     register int x, y, a, b, d, mask;
  92.     register int k1, k3, dx, dy;
  93.     int *addrl;
  94.     int *yorgl, *yorgol;
  95.     unsigned long pixel;
  96.     int nlwidth, yoffset, dyoffset;
  97.     int pmask;
  98.     register int *paddr;
  99.  
  100.     if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop ==
  101.     RROP_BLACK)
  102.     pixel = 0;
  103.     else
  104.     pixel = ~0L;
  105.  
  106.     if (pDraw->type == DRAWABLE_WINDOW)
  107.     {
  108.     addrl = (int *)
  109.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  110.     nlwidth = (int)
  111.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  112.     }
  113.     else
  114.     {
  115.     addrl = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  116.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  117.     }
  118.     do360 = miZeroArcSetup(arc, &info, TRUE);
  119.     yorgl = addrl + ((info.yorg + pDraw->y) * nlwidth);
  120.     yorgol = addrl + ((info.yorgo + pDraw->y) * nlwidth);
  121.     info.xorg += pDraw->x;
  122.     info.xorgo += pDraw->x;
  123.     MIARCSETUP();
  124.     yoffset = y ? nlwidth : 0;
  125.     dyoffset = 0;
  126.     mask = info.initialMask;
  127.     if (!(arc->width & 1))
  128.     {
  129.     DoPix(2, yorgl, info.xorgo);
  130.     DoPix(8, yorgol, info.xorgo);
  131.     }
  132.     if (!info.end.x || !info.end.y)
  133.     {
  134.     mask = info.end.mask;
  135.     info.end = info.altend;
  136.     }
  137.     if (do360 && (arc->width == arc->height) && !(arc->width & 1))
  138.     {
  139.     int xoffset = nlwidth;
  140.     int *yorghl = yorgl + (info.h * nlwidth);
  141.     int xorghp = info.xorg + info.h;
  142.     int xorghn = info.xorg - info.h;
  143.  
  144.     if (pixel)
  145.     {
  146.         while (1)
  147.         {
  148.         PixelateWhite(yorgl + yoffset, info.xorg + x);
  149.         PixelateWhite(yorgl + yoffset, info.xorg - x);
  150.         PixelateWhite(yorgol- yoffset, info.xorg - x);
  151.         PixelateWhite(yorgol - yoffset, info.xorg + x);
  152.         if (a < 0)
  153.             break;
  154.         PixelateWhite(yorghl - xoffset, xorghp - y);
  155.         PixelateWhite(yorghl - xoffset, xorghn + y);
  156.         PixelateWhite(yorghl + xoffset, xorghn + y);
  157.         PixelateWhite(yorghl + xoffset, xorghp - y);
  158.         xoffset += nlwidth;
  159.         MIARCCIRCLESTEP(yoffset += nlwidth;);
  160.         }
  161.     }
  162.     else
  163.     {
  164.         while (1)
  165.         {
  166.         PixelateBlack(yorgl + yoffset, info.xorg + x);
  167.         PixelateBlack(yorgl + yoffset, info.xorg - x);
  168.         PixelateBlack(yorgol- yoffset, info.xorg - x);
  169.         PixelateBlack(yorgol - yoffset, info.xorg + x);
  170.         if (a < 0)
  171.             break;
  172.         PixelateBlack(yorghl - xoffset, xorghp - y);
  173.         PixelateBlack(yorghl - xoffset, xorghn + y);
  174.         PixelateBlack(yorghl + xoffset, xorghn + y);
  175.         PixelateBlack(yorghl + xoffset, xorghp - y);
  176.         xoffset += nlwidth;
  177.         MIARCCIRCLESTEP(yoffset += nlwidth;);
  178.         }
  179.     }
  180.     x = info.w;
  181.     yoffset = info.h * nlwidth;
  182.     }
  183.     else if (do360)
  184.     {
  185.     while (y < info.h || x < info.w)
  186.     {
  187.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  188.         Pixelate(yorgl + yoffset, info.xorg + x);
  189.         Pixelate(yorgl + yoffset, info.xorgo - x);
  190.         Pixelate(yorgol - yoffset, info.xorgo - x);
  191.         Pixelate(yorgol - yoffset, info.xorg + x);
  192.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  193.     }
  194.     }
  195.     else
  196.     {
  197.     while (y < info.h || x < info.w)
  198.     {
  199.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  200.         if ((x == info.start.x) || (y == info.start.y))
  201.         {
  202.         mask = info.start.mask;
  203.         info.start = info.altstart;
  204.         }
  205.         DoPix(1, yorgl + yoffset, info.xorg + x);
  206.         DoPix(2, yorgl + yoffset, info.xorgo - x);
  207.         DoPix(4, yorgol - yoffset, info.xorgo - x);
  208.         DoPix(8, yorgol - yoffset, info.xorg + x);
  209.         if ((x == info.end.x) || (y == info.end.y))
  210.         {
  211.         mask = info.end.mask;
  212.         info.end = info.altend;
  213.         }
  214.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  215.     }
  216.     }
  217.     if ((x == info.start.x) || (y == info.start.y))
  218.     mask = info.start.mask;
  219.     DoPix(1, yorgl + yoffset, info.xorg + x);
  220.     DoPix(4, yorgol - yoffset, info.xorgo - x);
  221.     if (arc->height & 1)
  222.     {
  223.     DoPix(2, yorgl + yoffset, info.xorgo - x);
  224.     DoPix(8, yorgol - yoffset, info.xorg + x);
  225.     }
  226. }
  227.  
  228. void
  229. mfbZeroPolyArcSS(pDraw, pGC, narcs, parcs)
  230.     DrawablePtr    pDraw;
  231.     GCPtr    pGC;
  232.     int        narcs;
  233.     xArc    *parcs;
  234. {
  235.     register xArc *arc;
  236.     register int i;
  237.     BoxRec box;
  238.     RegionPtr cclip;
  239.  
  240.     if (!pGC->planemask & 1)
  241.     return;
  242.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  243.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  244.     {
  245.     if (miCanZeroArc(arc))
  246.     {
  247.         box.x1 = arc->x + pDraw->x;
  248.         box.y1 = arc->y + pDraw->y;
  249.         box.x2 = box.x1 + (int)arc->width + 1;
  250.         box.y2 = box.y1 + (int)arc->height + 1;
  251.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  252.         mfbZeroArcSS(pDraw, pGC, arc);
  253.         else
  254.         miZeroPolyArc(pDraw, pGC, 1, arc);
  255.     }
  256.     else
  257.         miPolyArc(pDraw, pGC, 1, arc);
  258.     }
  259. }
  260. @
  261.